package com.medical.sys.model;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class Resource {
    private String id;

    private String icon;

    private String name;

    private String description;

    private String type;

    private String url;

    private String permission;

    private String parentId = "0";

    private List<String> parentIds = new ArrayList<String>();
    private List<Resource> childen = new ArrayList<Resource>();

    private Boolean available;

    private Integer priority;

    private Boolean deleted;

    public List<String> roleIds = new ArrayList<String>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id == null ? null : id.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type == null ? null : type.trim();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission == null ? null : permission.trim();
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId == null ? null : parentId.trim();
    }

    public List<String> getParentIds() {
        return parentIds;
    }

    public void setParentIds(List<String> parentIds) {
        this.parentIds = parentIds;
    }

    public String getParentIdsStr(){
        if(CollectionUtils.isEmpty(parentIds)) {
            return "";
        }
        StringBuilder s = new StringBuilder();
        for(String resourceId : parentIds) {
            s.append(resourceId);
            s.append("/");
        }
        return s.toString();
    }

    public void setParentIdsStr(String parentIdsStr){
        if(StringUtils.isEmpty(parentIdsStr)) {
            return;
        }
        parentIds.clear();
        String[] resourceIdStrs = parentIdsStr.split("/");
        for(String resourceIdStr : resourceIdStrs) {
            if(StringUtils.isEmpty(resourceIdStr)) {
                continue;
            }
            parentIds.add(resourceIdStr);
        }
    }

    public String getSelfForParent(){
        return this.getParentIdsStr() + this.id + "/";
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public List<String> getRoleIds(){
        return roleIds;
    }

    public void setRoleIds(List<String> roleIds){
        this.roleIds = roleIds;
    }

    public List<Resource> getChilden() {
        return childen;
    }

    public void setChilden(List<Resource> childen) {
        this.childen = childen;
    }
}